<?php


$mode		= $this->uri->segment(4);
if ($mode == "edt" || $mode == "act_edt") {
	$act		= "act_edt";
	$idp		= $datpil->id;
	//$id_surat	= $datpil->id_surat;
	/*$kpd_yth	= $datpil->kpd_yth;
	$d['value'] = $datpil->kpd_yth;*/
	$isi_disposisi	= $datpil->isi_disposisi;
	$sifat		= $datpil->sifat;
	$batas_waktu= $datpil->batas_waktu;
	$catatan	= $datpil->catatan;
	$petunjuk	= $datpil->petunjuk;
	$id_disposisi	=  $datpil->id_disposisi;
	$arr_kpd = array();
	$arr_p = array();

	if (isset($kpd_yth) && $kpd_yth!=''){
		$arr_kpd=explode('_;', $kpd_yth);
	}
	if (isset($petunjuk) && $petunjuk!=''){
		$arr_p=explode('_;', $petunjuk);
	}
} else {
	$act		= "act_add";
	$idp		= "";
	$id_surat	= $this->uri->segment(3);
	$kpd_yth	= "";
	$isi_disposisi	= "";
	$sifat		= "";
	$batas_waktu= "";
	$catatan	= "";
	$id_disposisi	= "";
	$d=array();
}
?>
<div class="navbar navbar-inverse">
	<div class="container">
		<div class="navbar-header">
			<span class="navbar-brand" href="#">Disposisi Surat</span>
		</div>
	</div><!-- /.container -->
</div><!-- /.navbar -->

	<form action="<?=base_URL()?>admin/surat_disposisi/<?php echo $this->uri->segment(3)?>/<?php echo $act; ?>" method="post" accept-charset="utf-8" enctype="multipart/form-data">

	<input type="hidden" name="idp" value="<?php echo $this->uri->segment(3); ?>">
	<!-- <input type="hidden" name="id_surat" value="<?php /* echo $id_surat; */ ?>"> -->
	<input type="hidden" name="id_disposisi" value="<?php echo $id_disposisi; ?>">

	<b>Perihal Surat</b> : <i><?php echo $judul_surat; ?></i><br><br>

	<div class="row-fluid well" style="overflow: hidden">

	<div class="col-lg-6">
		<table width="100%" class="table-form">
		<tr>
			<td width="20%">Tujuan Disposisi</td>
			<td>

			<!-- <select name="kpd_yth" class="form-control">

				<?php /* echo $this->mdl_reff_unit->get_select_reff_unit($d); */ ?>
			</select> -->
			<?php
			//echo 'test-' . $idu1 . '-' . $idu2;

			if (($level_user=='Subdit') || ($level_user=='Sie') ){
				if ($mode == "edt" || $mode == "act_edt") {

					foreach ($reff_unit->result() as $row) {
						echo '<div class="checkbox">'
					    	.'<label>';
					    $check_kpd = '';
						foreach ($get_status_disposisi->result() as $row_sd) {
							if ($row_sd->kd_unit==$row->kd_unit){
								$check_kpd = 'checked';

							}

						}

						echo '<input type="checkbox" name="kpd_yth[]" value="' . $row->id .  '"' . $check_kpd . '> ' . $row->username . ' - ' . $row->nama . '';


					    echo '</label>'
					  		.'</div>';
					}

				}else{
					foreach ($reff_unit->result() as $row) {
						echo '<div class="checkbox">'
					    	.'<label>'
					      	.'<input type="checkbox" name="kpd_yth[]" value="' . $row->id . '"> ' . $row->username . ' - ' . $row->nama . ''
					    	.'</label>'
					  		.'</div>';
					}
				}
			}else{
				if ($mode == "edt" || $mode == "act_edt") {

					foreach ($reff_unit->result() as $row) {
						echo '<div class="checkbox">'
					    	.'<label>';
					    $check_kpd = '';
					    foreach ($get_status_disposisi->result() as $row_sd) {
							if ($row_sd->kd_unit==$row->kd_unit){
								$check_kpd = 'checked';

							}

						}
						/*for($i=0;$i<count($arr_kpd);$i++){
							if ($arr_kpd[$i]==$row->kd_unit){
								$check_kpd = 'checked';
								break;
							}

						}
*/
						echo '<input type="checkbox" name="kpd_yth[]" value="' . $row->kd_unit .  '"' . $check_kpd . '> ' . $row->nm_unit . '';


					    echo '</label>'
					  		.'</div>';
					}

				}else{
					foreach ($reff_unit->result() as $row) {
						echo '<div class="checkbox">'
					    	.'<label>'
					      	.'<input type="checkbox" name="kpd_yth[]" value="' . $row->kd_unit . '"> ' . $row->nm_unit . ''
					    	.'</label>'
					  		.'</div>';
					}
				}
			}
			?>
			</td>
		</tr>
		<tr><td width="20%">Isi Disposisi</td><td><b><textarea name="isi_disposisi" style="width: 400px; height: 60px" class="form-control"><?php echo $isi_disposisi; ?></textarea></b></td></tr>
		<tr>
			<td width="20%"></td>
			<td><b>

			</b></td>
		</tr>
		<tr>
			<td colspan="2">
			<br><button type="submit" class="btn btn-primary">Simpan</button>
			<a href="<?=base_URL()?>admin/surat_disposisi/<?php echo $this->uri->segment(3); ?>" class="btn btn-success">Kembali</a>
			</td>
		</tr>
		</table>
	</div>

	<div class="col-lg-6">
		<table width="100%" class="table-form">
			<tr><td width="20%">Sifat</td><td><b>
			<select name="sifat" class="form-control" style="width: 200px" ><option value=""> - Sifat - </option>
			<?php
				$l_sifat	= array('Biasa','Segera','Perlu Perhatian Khusus','Perhatian Batas Waktu');

				for ($i = 0; $i < sizeof($l_sifat); $i++) {
					if ($l_sifat[$i] == $sifat) {
						echo "<option selected value='".$l_sifat[$i]."'>".$l_sifat[$i]."</option>";
					} else {
						echo "<option value='".$l_sifat[$i]."'>".$l_sifat[$i]."</option>";
					}
				}
			?>
			</select>
			</b></td></tr>
			<tr><td width="20%">Batas Waktu</td><td><b><input type="text" name="batas_waktu" value="<?php echo $batas_waktu; ?>"  id="tgl_surat" style="width: 100px" class="form-control"></b></td></tr>
			<tr><td width="20%">Catatan</td><td><b><input type="text" name="catatan" value="<?php echo $catatan; ?>" style="width: 400px" class="form-control"></b></td></tr>
			<tr>
				<td width="20%">Petunjuk</td>
				<td><b>
					<?php
					if ($mode == "edt" || $mode == "act_edt") {


						foreach ($reff_petunjuk->result() as $row) {
							echo '<div class="checkbox">'
						    	.'<label>';
						    $check = '';
							for($n=0;$n<count($arr_p);$n++){
								//echo $arr_p[$n] . '<br/>';
								if ($arr_p[$n]==$row->id){
									$check = 'checked';
									break;
								}

							}

							echo '<input type="checkbox" name="petunjuk[]" value="' . $row->id .  '_"' . $check . '> ' . $row->nama . '';


						    echo '</label>'
						  		.'</div>';
						}
					}else{
						foreach ($reff_petunjuk->result() as $row) {

							echo '<div class="checkbox">'
						    	.'<label>'
						      	.'<input type="checkbox" name="petunjuk[]" value="' . $row->id . '_"> ' . $row->nama . ''
						    	.'</label>'
						  		.'</div>';
						}
					}
					?>
				</b></td>
			</tr>
		</table>
	</div>


	</div>

	</form>